﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SynoManager.Rss;

namespace SynoManager.DownloadStation.Search
{
    public abstract class RssSearchResult : SearchResultBase
    {
        protected readonly RssItem item;

        public RssSearchResult(RssSearchEngineBase engine, RssItem item)
            :base(engine)
        {
            this.item = item;

            this.title = item.Title;
            this.moreInfoUrl = item.Link.ToString();
        }

        #region Protected Fields
        protected string title;
        protected string downloadUrl;
        protected string moreInfoUrl;
        protected int seeders = -1;
        protected int leechers = -1;
        #endregion

        #region Public Properties
        public override string Title
        {
            get
            {
                if (ResultMode == ResultMode.Full && String.IsNullOrEmpty(title))
                    LoadTitle();
                return title;
            }
        }

        public override string DownloadUrl
        {
            get
            {
                if (ResultMode == ResultMode.Full && downloadUrl == null)
                    LoadDownloadUrl();
                return downloadUrl;
            }
        }

        public override string MoreInfoUrl
        {
            get
            {
                if (ResultMode == ResultMode.Full && moreInfoUrl == null)
                    LoadMoreInfoUrl();
                return moreInfoUrl;
            }
        }

        public override int Seeders
        {
            get
            {
                if (ResultMode == ResultMode.Full && seeders == -1)
                    LoadSeedersLeechers();
                return seeders;
            }
        }

        public override int Leechers
        {
            get
            {
                if (ResultMode == ResultMode.Full && leechers == -1)
                    LoadSeedersLeechers();
                return leechers;
            }
        }
        #endregion

        #region Virtual loader methods
        protected virtual void LoadTitle()
        {
            LoadFull();
        }

        protected virtual void LoadDownloadUrl()
        {
            LoadFull();
        }

        protected virtual void LoadMoreInfoUrl()
        {
            LoadFull();
        }

        protected virtual void LoadSeedersLeechers()
        {
            LoadFull();
        }
        #endregion

        protected abstract void LoadFull();
    }
}
